The Event Manager reports keyboard events one at a time at your application's request when you use the WaitNextEvent (WaitNextEvent) , EventAvail (EventAvail) , or GetNextEvent (GetNextEvent) function. In addition to getting keyboard events when the user presses or releases a key, you can directly read the keyboard (and keypad) at any time using the GetKeys function (GetKeys) .
You can also use the KeyTranslate function (KeyTranslate) to convert virtual key codes to character code values using a specified ' KCHR ' resource.
You can use the GetKeys function to obtain the current state of the keyboard.
pascal void GetKeys (KeyMap theKeys);
You can use the KeyTranslate function to convert a virtual key code to a character code based on a 'KCHR' resource. The KeyTranslate function is also available as the KeyTrans function.
pascal long KeyTranslate (const void *transData,
UInt16 keycode,
UInt32 *state);
The KeyTranslate function returns a 32-bit value that gives the character code for the virtual key code specified by the keycode parameter. Figure 1 shows the structure of the 32-bit number that KeyTranslate returns.
Figure 1 Structure of the KeyTranslate function result
The KeyTranslate function returns the values that correspond to one or possibly two characters that are generated by the specified virtual key code. For example, a given virtual key code might correspond to an alphabetic character with a separate accent character. For example, when the user presses Option-E followed by N, you can map this through the KeyTranslate function using the U.S. 'KCHR' resource to produce ´n, which KeyTranslate returns as two characters in the bytes labeled Character code 1 and Character code 2. If KeyTranslate returns only one character code, it is always in the byte labeled Character code 2. However, your application should always check both bytes labeled Character code 1 and Character code 2 in Figure 1 for possible values that map to the virtual key code.